package com.example.tests;

import static com.example.tests.ContactInfoGenerator.loadContactsFromCsvFile;
import static com.example.tests.ContactInfoGenerator.loadContactsFromXmlFile;
import static org.testng.Assert.assertEquals;

import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.Iterator;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.util.List;
import com.example.utils.SortedListOf;

public class ContactCreationTests extends TestBase {

  @DataProvider
  public Iterator<Object[]> contactsFromFile() throws IOException {
	return wrapContactsForDataProvider(loadContactsFromXmlFile(new File("contacts.xml"))).iterator();
	//return wrapContactsForDataProvider(loadContactsFromCsvFile(new File("contacts.txt"))).iterator();
  }
	
  @Test(dataProvider = "contactsFromFile")
  public void testContactCreationWithValidData(ContactInfo contact) throws Exception {
	
	SortedListOf<ContactInfo> oldList = app.getContactHelper().getContacts();

	app.getContactHelper().createContact(contact);
	
	SortedListOf<ContactInfo> newList = app.getContactHelper().getContactsFromUI();
    
    oldList.add(contact);
    assertEquals(newList,oldList);
    
  }
  
}
